home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / files / standard file / standardgetfolder / fspcompat.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  16.6 KB  |  491 lines

  1. /*
  2.     File:        FSpCompat.h
  3.     
  4.     Description:FSSpec compatibility functions.
  5.  
  6.     Author:        JL
  7.  
  8.     Copyright:     Copyright: © 1992-1999 by Apple Computer, Inc.
  9.                 all rights reserved.
  10.     
  11.     Disclaimer:    You may incorporate this sample code into your applications without
  12.                 restriction, though the sample code has been provided "AS IS" and the
  13.                 responsibility for its operation is 100% yours.  However, what you are
  14.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  15.                 after having made changes. If you're going to re-distribute the source,
  16.                 we require that you make it clear in the source that the code was
  17.                 descended from Apple Sample Code, but that you've made changes.
  18.     
  19.     Change History (most recent first):
  20.                 6/25/99    Updated for Metrowerks Codewarror Pro 2.1(KG)
  21.  
  22. */
  23.  
  24. #ifndef __FSPCOMPAT__
  25. #define __FSPCOMPAT__
  26.  
  27. #include <Types.h>
  28. #include <Files.h>
  29.  
  30. #include "Optimization.h"
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. /*****************************************************************************/
  37.  
  38. pascal    OSErr    FSMakeFSSpecCompat(short vRefNum,
  39.                                    long dirID,
  40.                                    ConstStr255Param fileName,
  41.                                    FSSpec *spec);
  42. /*    ¶ Initialize a FSSpec record.
  43.     The FSMakeFSSpecCompat function fills in the fields of an FSSpec record.
  44.     If the file system can't create the FSSpec, then the compatibility code
  45.     creates a FSSpec that is exactly like an FSSpec except that spec.name
  46.     for a file may not have the same capitalization as the file's catalog
  47.     entry on the disk volume. That is because fileName is parsed to get the
  48.     name instead of getting the name back from the file system. This works
  49.     fine with System 6 where FSMakeSpec isn't available.
  50.     
  51.     vRefNum        input:    Volume specification.
  52.     dirID        input:    Directory ID.
  53.     fileName    input:    Pointer to object name, or nil when dirID specifies
  54.                         a directory that's the object.
  55.     spec        output:    A file system specification to be filled in by
  56.                         FSMakeFSSpecCompat.
  57.     
  58.     Result Codes
  59.         noErr                0        No error    
  60.         nsvErr                -35        Volume doesn’t exist    
  61.         fnfErr                -43        File or directory does not exist
  62.                                     (FSSpec is still valid)    
  63. */
  64.  
  65. /*****************************************************************************/
  66.  
  67. pascal    OSErr    FSpOpenDFCompat(const FSSpec *spec,
  68.                                 char permission,
  69.                                 short *refNum);
  70. /*    ¶ Open a file's data fork.
  71.     The FSpOpenDFCompat function opens the data fork of the file specified
  72.     by spec.
  73.     Differences from FSpOpenDF: If FSpOpenDF isn't available,
  74.     FSpOpenDFCompat uses PHBOpen because System 6 doesn't support PBHOpenDF.
  75.     This means FSpOpenDFCompat could accidentally open a driver if the
  76.     spec->name begins with a period.
  77.     
  78.     spec        input:    An FSSpec record specifying the file whose data
  79.                         fork is to be opened.
  80.     permission    input:    A constant indicating the desired file access
  81.                         permissions.
  82.     refNum        output:    A reference number of an access path to the file's
  83.                         data fork.
  84.     
  85.     Result Codes
  86.         noErr                0        No error    
  87.         nsvErr                -35        No such volume    
  88.         ioErr                -36        I/O error    
  89.         bdNamErr            -37        Bad filename    
  90.         tmfoErr                -42        Too many files open    
  91.         fnfErr                -43        File not found    
  92.         opWrErr                -49        File already open for writing    
  93.         permErr                -54        Attempt to open locked file for writing    
  94.         dirNFErr            -120    Directory not found or incomplete pathname
  95.         afpAccessDenied        -5000    User does not have the correct access to
  96.                                     the file
  97.     
  98.     __________
  99.     
  100.     See also:    FSpOpenAware
  101. */
  102.  
  103. /*****************************************************************************/
  104.  
  105. pascal    OSErr    FSpOpenRFCompat(const FSSpec *spec,
  106.                                 char permission,
  107.                                 short *refNum);
  108. /*    ¶ Open a file's resource fork.
  109.     The FSpOpenRFCompat function opens the resource fork of the file
  110.     specified by spec.
  111.     
  112.     spec        input:    An FSSpec record specifying the file whose resource
  113.                         fork is to be opened.
  114.     permission    input:    A constant indicating the desired file access
  115.                         permissions.
  116.     refNum        output:    A reference number of an access path to the file's
  117.                         resource fork.
  118.     
  119.     Result Codes
  120.         noErr                0        No error    
  121.         nsvErr                -35        No such volume    
  122.         ioErr                -36        I/O error    
  123.         bdNamErr            -37        Bad filename    
  124.         tmfoErr                -42        Too many files open    
  125.         fnfErr                -43        File not found    
  126.         opWrErr                -49        File already open for writing    
  127.         permErr                -54        Attempt to open locked file for writing    
  128.         dirNFErr            -120    Directory not found or incomplete pathname
  129.         afpAccessDenied        -5000    User does not have the correct access to
  130.                                     the file
  131.     
  132.     __________
  133.     
  134.     See also:    FSpOpenRFAware
  135. */
  136.  
  137.  
  138. /*****************************************************************************/
  139.  
  140. pascal    OSErr    FSpCreateCompat(const FSSpec *spec,
  141.                                 OSType creator,
  142.                                 OSType fileType,
  143.                                 ScriptCode scriptTag);
  144. /*    ¶ Create a new file.
  145.     The FSpCreateCompat function creates a new file with the specified
  146.     type, creator, and script code.
  147.     Differences from FSpCreate: FSpCreateCompat correctly sets the
  148.     fdScript in the file's FXInfo record to scriptTag if the problem
  149.     isn't fixed in the File Manager code.
  150.     
  151.     spec        input:    An FSSpec record specifying the file to create.
  152.     creator        input:    The creator of the new file.
  153.     fileType    input    The file type of the new file.
  154.     scriptCode    input:    The code of the script system in which the file
  155.                         name is to be displayed.
  156.     
  157.     Result Codes
  158.         noErr                0        No error    
  159.         dirFulErr            -33        File directory full    
  160.         dskFulErr            -34        Disk is full    
  161.         nsvErr                -35        No such volume    
  162.         ioErr                -36        I/O error    
  163.         bdNamErr            -37        Bad filename    
  164.         fnfErr                -43        Directory not found or incomplete pathname    
  165.         wPrErr                -44        Hardware volume lock    
  166.         vLckdErr            -46        Software volume lock    
  167.         dupFNErr            -48        Duplicate filename and version    
  168.         dirNFErrdirNFErr    -120    Directory not found or incomplete pathname    
  169.         afpAccessDenied        -5000    User does not have the correct access    
  170.         afpObjectTypeErr    -5025    A directory exists with that name    
  171. */
  172.  
  173. /*****************************************************************************/
  174.  
  175. pascal    OSErr    FSpDirCreateCompat(const FSSpec *spec,
  176.                                    ScriptCode scriptTag,
  177.                                    long *createdDirID);
  178. /*    ¶ Create a new directory.
  179.     The FSpDirCreateCompat function creates a new directory and returns the
  180.     directory ID of the newDirectory.
  181.     
  182.     spec            input:    An FSSpec record specifying the directory to
  183.                             create.
  184.     scriptCode        input:    The code of the script system in which the
  185.                             directory name is to be displayed.
  186.     createdDirID    output:    The directory ID of the directory that was
  187.                             created.
  188.     
  189.     Result Codes
  190.         noErr                0        No error    
  191.         dirFulErr            -33        File directory full    
  192.         dskFulErr            -34        Disk is full    
  193.         nsvErr                -35        No such volume    
  194.         ioErr                -36        I/O error    
  195.         bdNamErr            -37        Bad filename    
  196.         fnfErr                -43        Directory not found or incomplete pathname    
  197.         wPrErr                -44        Hardware volume lock    
  198.         vLckdErr            -46        Software volume lock    
  199.         dupFNErr            -48        Duplicate filename and version    
  200.         dirNFErrdirNFErr    -120    Directory not found or incomplete pathname    
  201.         wrgVolTypErr        -123    Not an HFS volume    
  202.         afpAccessDenied        -5000    User does not have the correct access    
  203. */
  204.  
  205. /*****************************************************************************/
  206.  
  207. pascal    OSErr    FSpDeleteCompat(const FSSpec *spec);
  208. /*    ¶ Delete a file or directory.
  209.     The FSpDeleteCompat function deletes a file or directory.
  210.     
  211.     spec            input:    An FSSpec record specifying the file or 
  212.                             directory to delete.
  213.     
  214.     Result Codes
  215.         noErr                0        No error    
  216.         nsvErr                -35        No such volume    
  217.         ioErr                -36        I/O error    
  218.         bdNamErr            -37        Bad filename    
  219.         fnfErr                -43        File not found    
  220.         wPrErr                -44        Hardware volume lock    
  221.         fLckdErr            -45        File is locked    
  222.         vLckdErr            -46        Software volume lock    
  223.         fBsyErr                -47        File busy, directory not empty, or
  224.                                     working directory control block open    
  225.         dirNFErrdirNFErr    -120    Directory not found or incomplete pathname    
  226.         afpAccessDenied        -5000    User does not have the correct access    
  227. */
  228.  
  229. /*****************************************************************************/
  230.  
  231. pascal    OSErr    FSpGetFInfoCompat(const FSSpec *spec,
  232.                                   FInfo *fndrInfo);
  233. /*    ¶ Get the finder information for a file.
  234.     The FSpGetFInfoCompat function gets the finder information for a file.
  235.  
  236.     spec        input:    An FSSpec record specifying the file.
  237.     fndrInfo    output:    If the object is a file, then its FInfo.
  238.     
  239.     Result Codes
  240.         noErr                0        No error    
  241.         nsvErr                -35        No such volume    
  242.         ioErr                -36        I/O error    
  243.         bdNamErr            -37        Bad filename    
  244.         fnfErr                -43        File not found    
  245.         paramErr            -50        No default volume    
  246.         dirNFErrdirNFErr    -120    Directory not found or incomplete pathname    
  247.         afpAccessDenied        -5000    User does not have the correct access    
  248.         afpObjectTypeErr    -5025    Directory not found or incomplete pathname    
  249.     
  250.     __________
  251.     
  252.     Also see:    FSpGetDInfo
  253. */
  254.  
  255. /*****************************************************************************/
  256.  
  257. pascal    OSErr    FSpSetFInfoCompat(const FSSpec *spec,
  258.                                   const FInfo *fndrInfo);
  259. /*    ¶ Set the finder information for a file.
  260.     The FSpSetFInfoCompat function sets the finder information for a file.
  261.  
  262.     spec        input:    An FSSpec record specifying the file.
  263.     fndrInfo    input:    The FInfo.
  264.     
  265.     Result Codes
  266.         noErr                0        No error    
  267.         nsvErr                -35        No such volume    
  268.         ioErr                -36        I/O error    
  269.         bdNamErr            -37        Bad filename    
  270.         fnfErr                -43        File not found    
  271.         wPrErr                -44        Hardware volume lock    
  272.         fLckdErr            -45        File is locked    
  273.         vLckdErr            -46        Software volume lock    
  274.         dirNFErrdirNFErr    -120    Directory not found or incomplete pathname    
  275.         afpAccessDenied        -5000    User does not have the correct access    
  276.         afpObjectTypeErr    -5025    Object was a directory    
  277.     
  278.     __________
  279.     
  280.     Also see:    FSpSetDInfo
  281. */
  282.  
  283. /*****************************************************************************/
  284.  
  285. pascal    OSErr    FSpSetFLockCompat(const FSSpec *spec);
  286. /*    ¶ Lock a file.
  287.     The FSpSetFLockCompat function locks a file.
  288.  
  289.     spec        input:    An FSSpec record specifying the file.
  290.     
  291.     Result Codes
  292.         noErr                0        No error    
  293.         nsvErr                -35        No such volume    
  294.         ioErr                -36        I/O error    
  295.         fnfErr                -43        File not found    
  296.         wPrErr                -44        Hardware volume lock    
  297.         vLckdErr            -46        Software volume lock    
  298.         dirNFErrdirNFErr    -120    Directory not found or incomplete pathname    
  299.         afpAccessDenied        -5000    User does not have the correct access to
  300.                                     the file    
  301.         afpObjectTypeErr    -5025    Folder locking not supported by volume    
  302. */
  303.  
  304. /*****************************************************************************/
  305.  
  306. pascal    OSErr    FSpRstFLockCompat(const FSSpec *spec);
  307. /*    ¶ Unlock a file.
  308.     The FSpRstFLockCompat function unlocks a file.
  309.  
  310.     spec        input:    An FSSpec record specifying the file.
  311.     
  312.     Result Codes
  313.         noErr                0        No error    
  314.         nsvErr                -35        No such volume    
  315.         ioErr                -36        I/O error    
  316.         fnfErr                -43        File not found    
  317.         wPrErr                -44        Hardware volume lock    
  318.         vLckdErr            -46        Software volume lock    
  319.         dirNFErrdirNFErr    -120    Directory not found or incomplete pathname    
  320.         afpAccessDenied        -5000    User does not have the correct access to
  321.                                     the file    
  322.         afpObjectTypeErr    -5025    Folder locking not supported by volume    
  323. */
  324.  
  325. /*****************************************************************************/
  326.  
  327. pascal    OSErr    FSpRenameCompat(const FSSpec *spec,
  328.                                 ConstStr255Param newName);
  329. /*    ¶ Rename a file or directory.
  330.     The FSpRenameCompat function renames a file or directory.
  331.  
  332.     spec        input:    An FSSpec record specifying the file.
  333.     newName        input:    The new name of the file or directory.
  334.     
  335.     Result Codes
  336.         noErr                0        No error    
  337.         dirFulErr            -33        File directory full    
  338.         dskFulErr            -34        Volume is full    
  339.         nsvErr                -35        No such volume    
  340.         ioErr                -36        I/O error    
  341.         bdNamErr            -37        Bad filename    
  342.         fnfErr                -43        File not found    
  343.         wPrErr                -44        Hardware volume lock    
  344.         fLckdErr            -45        File is locked    
  345.         vLckdErr            -46        Software volume lock    
  346.         dupFNErr            -48        Duplicate filename and version    
  347.         paramErr            -50        No default volume    
  348.         fsRnErr                -59        Problem during rename    
  349.         dirNFErrdirNFErr    -120    Directory not found or incomplete pathname    
  350.         afpAccessDenied        -5000    User does not have the correct access to
  351.                                     the file    
  352. */
  353.  
  354. /*****************************************************************************/
  355.  
  356. pascal    OSErr    FSpCatMoveCompat(const FSSpec *source,
  357.                                  const FSSpec *dest);
  358. /*    ¶ Move a file or directory to a different location on on the same volume.
  359.     The FSpCatMoveCompat function moves a file or directory to a different
  360.     location on on the same volume.
  361.  
  362.     source        input:    An FSSpec record specifying the file or directory.
  363.     dest        input:    An FSSpec record specifying the name and location
  364.                         of the directory into which the source file or
  365.                         directory is to be moved.
  366.     
  367.     Result Codes
  368.         noErr                0        No error    
  369.         nsvErr                -35        No such volume    
  370.         ioErr                -36        I/O error    
  371.         bdNamErr            -37        Bad filename or attempt to move into
  372.                                     a file    
  373.         fnfErr                -43        File not found    
  374.         wPrErr                -44        Hardware volume lock    
  375.         fLckdErr            -45        Target directory is locked    
  376.         vLckdErr            -46        Software volume lock    
  377.         dupFNErr            -48        Duplicate filename and version    
  378.         paramErr            -50        No default volume    
  379.         badMovErr            -122    Attempt to move into offspring    
  380.         wrgVolTypErr        -123    Not an HFS volume    
  381.         afpAccessDenied        -5000    User does not have the correct access to
  382.                                     the file    
  383. */
  384.  
  385. /*****************************************************************************/
  386.  
  387. pascal    OSErr    FSpExchangeFilesCompat(const FSSpec *source,
  388.                                        const FSSpec *dest);
  389. /*    ¶ Exchange the data stored in two files on the same volume.
  390.     The FSpExchangeFilesCompat function swaps the data in two files by
  391.     changing the information in the volume's catalog and, if the files
  392.     are open, in the file control blocks.
  393.     Differences from FSpExchangeFiles: Correctly exchanges files on volumes
  394.     that don't support PBExchangeFiles. FSpExchangeFiles attempts to support
  395.     volumes that don't support PBExchangeFiles, but in System 7, 7.0.1, 7.1,
  396.     and 7 Pro, the compatibility code just doesn't work on volumes that
  397.     don't support PBExchangeFiles (even though you may get a noErr result).
  398.     System Update 3.0 and System 7.5 and later have the problems in
  399.     FSpExchangeFiles corrected.
  400.     
  401.     Result Codes
  402.         noErr                0        No error    
  403.         nsvErr                -35        Volume not found    
  404.         ioErr                -36        I/O error    
  405.         fnfErr                -43        File not found    
  406.         fLckdErr            -45        File is locked    
  407.         vLckdErr            -46        Volume is locked or read-only    
  408.         paramErr            -50        Function not supported by volume    
  409.         volOfflinErr        -53        Volume is offline    
  410.         wrgVolTypErr        -123    Not an HFS volume    
  411.         diffVolErr            -1303    Files on different volumes    
  412.         afpAccessDenied        -5000    User does not have the correct access    
  413.         afpObjectTypeErr    -5025    Object is a directory, not a file    
  414.         afpSameObjectErr    -5038    Source and destination files are the same    
  415. */
  416.  
  417. /*****************************************************************************/
  418.  
  419. pascal    short    FSpOpenResFileCompat(const FSSpec *spec,
  420.                                      SignedByte permission);
  421. /*    ¶ Open a file's resource file.
  422.     The FSpOpenResFileCompat function opens the resource file specified
  423.     by spec.
  424.     
  425.     spec            input:    An FSSpec record specifying the file whose
  426.                             resource file is to be opened.
  427.     permission        input:    A constant indicating the desired file access
  428.                             permissions.
  429.     function result    output:    A resource file reference number, or if there's
  430.                             an error -1.
  431.     
  432.     Result Codes
  433.         noErr                0        No error
  434.         nsvErr                –35        No such volume
  435.         ioErr                –36        I/O error
  436.         bdNamErr            –37        Bad filename or volume name (perhaps zero
  437.                                     length)
  438.         eofErr                –39        End of file
  439.         tmfoErr                –42        Too many files open
  440.         fnfErr                –43        File not found
  441.         opWrErr                –49        File already open with write permission
  442.         permErr                –54        Permissions error (on file open)
  443.         extFSErr            –58        Volume belongs to an external file system
  444.         memFullErr            –108    Not enough room in heap zone
  445.         dirNFErr            –120    Directory not found
  446.         mapReadErr            –199    Map inconsistent with operation
  447. */
  448.  
  449. /*****************************************************************************/
  450.  
  451. pascal    void    FSpCreateResFileCompat(const FSSpec *spec,
  452.                                        OSType creator,
  453.                                        OSType fileType,
  454.                                        ScriptCode scriptTag);
  455. /*    ¶ Create a resource file.
  456.     The FSpCreateResFileCompat function creates a new resource file with
  457.     the specified type, creator, and script code.
  458.     Differences from FSpCreateResFile: FSpCreateResFileCompat correctly
  459.     sets the fdScript in the file's FXInfo record to scriptTag if the
  460.     problem isn't fixed in the File Manager code.
  461.     
  462.     spec        input:    An FSSpec record specifying the resource file to create.
  463.     creator        input:    The creator of the new file.
  464.     fileType    input    The file type of the new file.
  465.     scriptCode    input:    The code of the script system in which the file
  466.                         name is to be displayed.
  467.     
  468.     Result Codes
  469.         noErr                0        No error
  470.         dirFulErr            –33        Directory full
  471.         dskFulErr            –34        Disk full
  472.         nsvErr                –35        No such volume
  473.         ioErr                –36        I/O error
  474.         bdNamErr            –37        Bad filename or volume name (perhaps zero
  475.                                     length)
  476.         tmfoErr                –42        Too many files open
  477.         wPrErrw                –44        Disk is write-protected
  478.         fLckdErr            –45        File is locked
  479. */
  480.  
  481. /*****************************************************************************/
  482.  
  483. #ifdef __cplusplus
  484. }
  485. #endif
  486.  
  487. #include "OptimizationEnd.h"
  488.  
  489. #endif    /* __FSPCOMPAT__ */
  490.  
  491.